define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/index' + location.search,
                    add_url: 'order/add',
                    edit_url: 'order/edit',
                    del_url: 'order/del',
                    multi_url: 'order/multi',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'userinfo.nickname', title: __('User_id')},
                        {field: 'userinfo.avatar', title: __('Image'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'name', title: __('Name')},
                        {field: 'image', title: __('Image'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'order_no', title: __('Order_no')},
                        {field: 'discount', title: __('Discount'), operate:'BETWEEN'},
                        {field: 'diyong', title: __('Diyong'), operate:'BETWEEN'},
                        {field: 'shop_id', title: __('Shop_id')},
                        {field: 'weigh', title: __('Weigh'), operate:'BETWEEN'},
                        {field: 'origin_price', title: __('Origin_price'), operate:'BETWEEN'},
                        {field: 'total_price', title: __('Total_price'), operate:'BETWEEN'},
                        {field: 'pay_status', title: __('Pay_status'), searchList: {"10":__('Pay_status 10'),"20":__('Pay_status 20'),"30":__('Pay_status 30'),"40":__('Pay_status 40'),"50":__('Pay_status 50')}, formatter: Table.api.formatter.status},
                        {field: 'pay_time', title: __('Pay_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'num', title: __('Num')},
                        {field: 'delivery_time', title: __('Delivery_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'company', title: __('Company')},
                        {field: 'address.name', title: '收件人'},
                        {field: 'address.phone', title: '收件人手机号码'},
                        {field: 'address.province', title: '省份'},
                        {field: 'address.city', title: '市'},
                        {field: 'address.region', title: '区'},
                        {field: 'address.detail', title: '详细地址'},
                        {field: 'track_number', title: __('Track_number')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});